<?php
$adm_menu = "1";

include("config.php");
if (!isset($_SESSION["auser"]) || $_SESSION["auser"] == "" || $_SESSION['agroup'] != "WEB_ADMIN") header('Location: index.php');

$db_www = new DB($server_username,$server_pass,$server_db,$server,$driver);
$db_rdata = new DB($rdata_server_username,$rdata_server_pass,$rdata_server_db,$rdata_server,$rdata_driver);

$err = "";
$imcode = "";
$impav = "";
if (isset($_REQUEST["findim"])){
		$test_q = "SELECT N08_kodas_ks,N08_PAV FROM n08_klij WHERE N08_kodas_ks = '".$_REQUEST["imcode"]."'";
		//echo $test_q; 
		$im = $db_www->returnInfo($test_q);	
		if ($im == null) {
			$impav = "";
			$imcode = "";
			$err .= "<br>Nerasta įmonė su tokiu kodu!";
		} else {
			$impav = iconv('windows-1257','UTF-8',$im["N08_PAV"]);
			$imcode = $_REQUEST["imcode"];
		}
}
if (isset($_REQUEST["act"]) && !isset($_REQUEST["findim"])){
		if ($_REQUEST["act"] == "activate") {
			$sql = "exec web_card_activate "			
			. "@action='ACTIVATE',"
			. "@kortele='".iconv('UTF-8','windows-1257', addslashes_mssql($_REQUEST["uid"]))."'";		
			$db_www->execute($sql);	
			
			logAction("Tiekėjas aktyvuoja:" . $_REQUEST["uid"],2);	
			header("Location: acards.php?submit=Rodyti");			
		} else if ($_REQUEST["act"] == "deactivate") {
			$sql = "exec web_card_activate "			
			. "@action='DEACTIVATE',"
			. "@kortele='".iconv('UTF-8','windows-1257', addslashes_mssql($_REQUEST["uid"]))."'";		
			$db_www->execute($sql);	
			
			logAction("Tiekėjas anuliuoja:" . $_REQUEST["uid"],2);	
			header("Location: acards.php?submit=Rodyti");			
		} else if ($_REQUEST["act"] == "save") {		
		    //ar yra toks imones kodas
		    $test_q = "SELECT N08_kodas_ks,N08_PAV FROM n08_klij WHERE N08_kodas_ks = '".$_REQUEST["imcode"]."'";
		    $im = $db_www->returnInfo($test_q);		
	    	if (empty($im)) {
			   $err .= "<br>Nerasta įmonė su tokiu kodu!";
		    }

			if ($_REQUEST["uid"] == "0") { //nauja
				//ar teisingas korteles numeris
				$cardnr = trim($_POST["cardnr"]);
				if (!is_numeric($cardnr) || (strlen ($cardnr) != 16 && strlen ($cardnr) != 19) || strrpos($cardnr, ".")) {
					$err .= "<br>Neteisingas kortelės numeris!";
				}
				//ar teisingas prefiksas
					$sql = "create table #tt_test(N51_PAV varchar(20))";
					$db_rdata->execute($sql);
					
					$sql = "insert into #tt_test values ('".addslashes_mssql($cardnr)."')";		
					$db_rdata->execute($sql);

					$sql = "select count(*) as cnt from #tt_test where ";					
					$sql .= $korteliu_prefiksas;
					
					
					$r = $db_rdata->returnInfo($sql);		
					if ($r["cnt"] != 1) {
					   $err .= "<br>Neteisingas kortelės prefiksas!";
					}
			
				//ar dar neegzistoja toks numeris tame tarpe anuliuotas
				$sql = "select count(*) as cnt from N51_SUTH where N51_PAV like '%".addslashes_mssql($cardnr)."%'";
				$r = $db_www->returnInfo($sql);	
	
				if ($r["cnt"] > 0) {
					   $err .= "<br>Kortelė tokiu numeriu jau egzistuoja!";
				}
				if ($err == ""){ //jei nebuvo klaidu
				    
					//iterpiam i rivile
                    $sql = "create table #ttrez(result varchar(255))";
					$db_www->execute($sql);
					$knew_query = str_replace("<pastabos>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pin"].";".$_REQUEST["pav"])), $knew_query);
					$knew_query = str_replace("<kortele>", @iconv('UTF-8','windows-1257',addslashes_mssql($cardnr)), $knew_query);
					$knew_query = str_replace("<kodas>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["imcode"])), $knew_query);
                    
					$db_www->execute($knew_query);
					$sql = "select * from #ttrez";
				    $r = $db_www->returnInfo($sql);	

					if (!empty($r) && $r["result"]!=null){ 
						//iterpiam i rdata		
							
						$kchange_query_rdata = str_replace("<kortele>", $r["result"], $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<nuo>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["nuo"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<iki>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["iki"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<credit>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["crlimit"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<p1>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp1"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<p2>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp2"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<p3>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp3"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<p4>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp4"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<p5>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp5"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<p6>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp6"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<p7>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp7"])), $kchange_query_rdata);
						$kchange_query_rdata = str_replace("<lustas>", @iconv('UTF-8','windows-1257',"'".addslashes_mssql($_REQUEST["lustas"])."'"), $kchange_query_rdata);

						
						
						$db_rdata->execute($kchange_query_rdata);

						logAction("Administratorius sukūrė:" . $cardnr,3);

						header("Location: acards.php?submit=Rodyti");
                    }	else {
						$err .= "<br>Nepavyko iterpti korteles!";	
						}
				}
			} else { //redagavimas

			
				if ($err == ""){ //jei nebuvo klaidu
			
					$kchange_query = str_replace("KLIENT", "ADMIN", $kchange_query);
					$kchange_query = str_replace("<pastabos>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pin"].";".$_REQUEST["pav"])), $kchange_query);
					$kchange_query = str_replace("<kortele>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["uid"])), $kchange_query);
					$kchange_query = str_replace("<kodas>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["imcode"])), $kchange_query);

					$kchange_query_rdata = str_replace("<kortele>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["uid"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<nuo>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["nuo"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<iki>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["iki"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<credit>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["crlimit"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<p1>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp1"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<p2>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp2"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<p3>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp3"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<p4>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp4"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<p5>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp5"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<p6>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp6"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<p7>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["pp7"])), $kchange_query_rdata);
					$kchange_query_rdata = str_replace("<lustas>", @iconv('UTF-8','windows-1257',"'".addslashes_mssql($_REQUEST["lustas"])."'"), $kchange_query_rdata);

					
					$db_www->execute($kchange_query);
					$db_rdata->execute($kchange_query_rdata);
					logAction("Administratorius koreguoja:" . $_REQUEST["uid"],3);

					header("Location: acards.php?submit=Rodyti");
				}
			}
	}
}	
include("header.php");
include("menu.php");




	if (isset($_REQUEST["uid"]) && $_REQUEST["uid"] != "0") {
		$uid = @iconv('UTF-8','windows-1257',$_REQUEST["uid"]);
		$tit = "Kortelės redagavimas";	
		if (!isset($_POST["uid"])){
			$sql = "select * from n51_suth_c where N51_c_kodas_kt= '".addslashes_mssql($uid)."'";
			$info = $db_rdata->returnInfo($sql);	
		
			$sql = "SELECT case when (CHARINDEX (';',cast(N51_PASTABOS as varchar(8000)))=5) THEN
SUBSTRING(cast(N51_PASTABOS as varchar(8000)),6,1000) else case when (CHARINDEX (';',cast(N51_PASTABOS as varchar(8000)))=1) then SUBSTRING(cast(N51_PASTABOS as varchar(8000)),2,1000) else
cast(N51_PASTABOS as varchar(8000)) END END as N51_KORTA,
case when (CHARINDEX (';',cast(N51_PASTABOS as varchar(8000)))=5) then 
SUBSTRING(cast(N51_PASTABOS as varchar(8000)),1,4) 
else 
''
end as N51_PIN,n60_kodas_sm,n60_pav2,N51_PAV,CASE WHEN SUBSTRING(N51_PAV,1,1)='_'  THEN 0 ELSE 1 END as aktyvi FROM N60_asm a,N51_SUTH WHERE N51_KODAS_KS=a.N60_KODAS_KS AND N51_KODAS_KT = '".addslashes_mssql($uid)."'";
			$card = $db_www->returnInfo($sql);
			
			if (!empty($card)) {
				$pav = @iconv('windows-1257', 'UTF-8', $card["N51_KORTA"]);
				$pin = $card["N51_PIN"];
				$imcode = trim($card["n60_kodas_sm"]);
				$impav = @iconv('windows-1257', 'UTF-8', trim($card["n60_pav2"]));
				$cardnr = @iconv('windows-1257', 'UTF-8', trim($card["N51_PAV"]));
				$active = $card["aktyvi"];
			} else {
				$pav = "";
				$pin = "";
				$imcode = "";
				$impav = "";
				$cardnr = "";
				$active = 0;
			}
			
			if (!empty($info)) {
				
				$crlimit = $info["N51_c_limitas"];
				$nuo = $info["n51_valanda_nuo"];
				$iki = $info["n51_valanda_iki"];
				$p1 = $info["n51_pirmadienis"];
				$p2 = $info["n51_antradienis"];
				$p3 = $info["n51_treciadienis"];
				$p4 = $info["n51_ketvirtadienis"];
				$p5 = $info["n51_penktadienis"];
				$p6 = $info["n51_sestadienis"];
				$p7 = $info["n51_sekmadienis"];
				$lustas = trim($info["n51_lustas"]);
			} else {
				$crlimit = "";
				$nuo = "";
				$iki = "";
				$p1 = "0";
				$p2 = "0";
				$p3 = "0";
				$p4 = "0";
				$p5 = "0";
				$p6 = "0";
				$p7 = "0";
				$lustas = "";
			}
		} else {
				$pav = $_POST["pav"];
				$pin = $_POST["pin"];
				$crlimit = $_POST["crlimit"];
				$nuo = $_POST["nuo"];
				$iki = $_POST["iki"];
				$lustas = $_POST["lustas"];
				$imcode = $_POST["imcode"];
					
				$cardnr = $_POST["cardnr"];	
				$active = $_POST["active"];					
				if (isset($_POST["p1"]) && $_POST["p1"]=="on") $p1 ="1"; else $p1 = "0";
				if (isset($_POST["p2"]) && $_POST["p2"]=="on") $p2 ="1"; else $p2 = "0";
				if (isset($_POST["p3"]) && $_POST["p3"]=="on") $p3 ="1"; else $p3 = "0";
				if (isset($_POST["p4"]) && $_POST["p4"]=="on") $p4 ="1"; else $p4 = "0";
				if (isset($_POST["p5"]) && $_POST["p5"]=="on") $p5 ="1"; else $p5 = "0";
				if (isset($_POST["p6"]) && $_POST["p6"]=="on") $p6 ="1"; else $p6 = "0";
				if (isset($_POST["p7"]) && $_POST["p7"]=="on") $p7 ="1"; else $p7 = "0";
				
		}
	} else {
		$uid = "0";
		$tit = "Kortelės įvedimas";
		
		if (!isset($_POST["uid"])){
			$pav = "";
			$pin = "";
			$crlimit = "";
			$nuo = "";
			$iki = "";
			$p1 = "0";
			$p2 = "0";
			$p3 = "0";
			$p4 = "0";
			$p5 = "0";
			$p6 = "0";
			$p7 = "0";	
			$lustas = "";
		
			$cardnr = "";
			$active = 0;
		} else {
			$pav = $_POST["pav"];
			$pin = $_POST["pin"];
			$crlimit = $_POST["crlimit"];
			$nuo = $_POST["nuo"];
			$iki = $_POST["iki"];
			$lustas = $_POST["lustas"];
			$imcode = $_POST["imcode"];
				
			$cardnr = $_POST["cardnr"];	
			$active = $_POST["active"];					
			if (isset($_POST["p1"]) && $_POST["p1"]=="on") $p1 ="1"; else $p1 = "0";
			if (isset($_POST["p2"]) && $_POST["p2"]=="on") $p2 ="1"; else $p2 = "0";
			if (isset($_POST["p3"]) && $_POST["p3"]=="on") $p3 ="1"; else $p3 = "0";
			if (isset($_POST["p4"]) && $_POST["p4"]=="on") $p4 ="1"; else $p4 = "0";
			if (isset($_POST["p5"]) && $_POST["p5"]=="on") $p5 ="1"; else $p5 = "0";
			if (isset($_POST["p6"]) && $_POST["p6"]=="on") $p6 ="1"; else $p6 = "0";
			if (isset($_POST["p7"]) && $_POST["p7"]=="on") $p7 ="1"; else $p7 = "0";		
		}
	}
	

	



?>
<script>
function validateForm(myform)
{
	pin = document.getElementById("pin");
		if (!isUnsignedInteger(pin.value)) {
			alert("PIN kodas turi būti skaičius");
			return;
		}	
		if (pin.value.length == 0) pin.value = "0000";
		else if (pin.value.length == 1) pin.value = "000" + pin.value;
		else if (pin.value.length == 2) pin.value = "00" + pin.value;
		else if (pin.value.length == 3) pin.value = "0" + pin.value;
		
	credit = document.getElementById("crlimit").value.trim();
		if (credit != "") {
			if (!isUnsignedInteger(credit)) {
				alert("Neteisingas kredito limitas");
				return;
			}
		}	
	nuo = document.getElementById("nuo").value.trim();
	iki = document.getElementById("iki").value.trim();
		if (nuo != "") {
			if (!isUnsignedInteger(nuo)) {
				alert("Nuo valanda turi būti 0-24");
				return;
			} else {
				p = parseInt(nuo);
				if (p > 24 || p < 0){
					alert("Nuo valanda turi būti 0-24");
					return;				
				}
			}
		}
		if (iki != "") {
			if (!isUnsignedInteger(iki)) {
				alert("Iki valanda turi būti 0-24");
				return;
			} else {
				p = parseInt(iki);
				if (p > 24 || p < 0){
					alert("Iki valanda turi būti 0-24");
					return;				
				}
			}
		}	
	
	
	
	p1 = document.getElementById("p1");
	pp1 = document.getElementById("pp1");
	if (p1.checked==true) pp1.value = "1"; else pp1.value = "0";
	p2 = document.getElementById("p2");
	pp2 = document.getElementById("pp2");
	if (p2.checked==true) pp2.value = "1"; else pp2.value = "0";
	p3 = document.getElementById("p3");
	pp3 = document.getElementById("pp3");
	if (p3.checked==true) pp3.value = "1"; else pp3.value = "0";
	p4 = document.getElementById("p4");
	pp4 = document.getElementById("pp4");
	if (p4.checked==true) pp4.value = "1"; else pp4.value = "0";
	p5 = document.getElementById("p5");
	pp5 = document.getElementById("pp5");
	if (p5.checked==true) pp5.value = "1"; else pp5.value = "0";
	p6 = document.getElementById("p6");
	pp6 = document.getElementById("pp6");
	if (p6.checked==true) pp6.value = "1"; else pp6.value = "0";
	p7 = document.getElementById("p7");
	pp7 = document.getElementById("pp7");
	if (p7.checked==true) pp7.value = "1"; else pp7.value = "0";	
	myform.submit();
}

function isUnsignedInteger(s) {
  return (s.toString().search(/^[0-9]+$/) == 0);
}

function status(n,nr)
{
    if (n == "1") {
		var answer = confirm("Ar aktyvuoti kortelę?")
		if (answer){
			window.location='acard.php?act=activate&uid='+nr ;
		}
	} else {
		var answer = confirm("Ar anuliuoti kortelę?")
		if (answer){
			window.location='acard.php?act=deactivate&uid='+nr ;
		}
	}	
}

</script>
<form method="post" name='forma' action='acard.php?act=save'>
<input id="pp1" type="hidden" name="pp1">
<input id="pp2" type="hidden" name="pp2">
<input id="pp3" type="hidden" name="pp3">
<input id="pp4" type="hidden" name="pp4">
<input id="pp5" type="hidden" name="pp5">
<input id="pp6" type="hidden" name="pp6">
<input id="pp7" type="hidden" name="pp7">

<input id="uid" type="hidden" name="uid" value="<?php echo @iconv('windows-1257','UTF-8',$uid);?>">
<input id="active" type="hidden" name="active" value="<?php echo $active?>">
<table class="innercont" cellspacing="0" cellpadding="10" border="0">
<tr><td class="leftcol2">
<input class='but bgwhite nopad' type = "submit" value = "Išsaugoti" onclick="validateForm('forma');return false;"><br><br>
<Button id='unblockButton' class='but bgwhite nopad' onclick="window.location='acards.php?submit=Rodyti';return false;">Atgal</Button>
</td><td class="centercol">
<?php
if ($err != ""){
	echo "<p style='background-color:transparent;color:red;font-weight:bold;font-size:10px;'>".$err."</p>";
}
?>

<div class="title2"><?php echo $tit?></div>
<table width="100%" border="0">
<tr><td valign="top" colspan="2" class="fieldtitle">Įmonės pavadinimas:</td><td valign="top" class="fieldtitle">Įmonės kodas:</td></tr>
<tr>
<td valign="top" colspan="2">
<input style="width:275px;" id='impav' class="inp" type='text' name="pav" value="<?php echo htmlspecialchars($impav)?>" readonly="readonly">
</td>
<td valign="top">
<input id='imcode' class="inp" type='text' name="imcode" value="<?php echo htmlspecialchars($imcode) ?>"><br>
<div style="float:right;"><A class='flink' href="#" onclick='document.forma.action="acard.php?act=save&findim=1";document.forma.submit()'>Ieškoti</A></div>
</td></tr>
<tr><td valign="top" colspan="2" class="fieldtitle">Kortelės numeris:</td><td valign="top" class="fieldtitle"></td></tr>
<tr>
<td valign="top" colspan="2">
<input style="width:275px;" id='cardnr' class="inp" type='text' name="cardnr" value="<?php echo htmlspecialchars($cardnr)?>" <?php if ($uid != "0") echo 'readonly="readonly"'; ?>>
</td>
<td valign="middle">
<?php
if ($uid != "0") {
	if ($active == 0) {
		?>
		<button id="unblockButton" class="but bgwhite nopad" onclick="status('1','<?php echo @iconv('windows-1257','UTF-8',$uid);?>');return false;">Aktyvuoti kortelę</button>
		<?php
	} else {
		?>
		<button id="unblockButton" class="but bgwhite nopad" onclick="status('0','<?php echo @iconv('windows-1257','UTF-8',$uid);?>');return false;">Anuliuoti kortelę</button>
		<?php
	}
}
?>
</td></tr>


<tr><td valign="top" colspan="2" class="fieldtitle">Kortelės pavadinimas:</td><td valign="top" class="fieldtitle"></td></tr>
<tr>
<td valign="top" colspan="2">
<input style="width:275px;" id='pav' class="inp" type='text' name="pav" value="<?php echo htmlspecialchars($pav)?>">
</td>
<td valign="top">

</td></tr>
<tr><td valign="top" colspan="2" class="fieldtitle">Lusto numeris:</td><td valign="top" class="fieldtitle">PIN kodas:</td></tr>
<tr>
<td valign="top" colspan="2">
<input style="width:275px;" id='lustas' class="inp" type='text' name="lustas" value="<?php echo htmlspecialchars($lustas)?>">
</td>
<td valign="top">
<input name="pin" id="pin" class="inp" MAXLENGTH=4 type="text" value="<?php echo htmlspecialchars($pin);?>">
</td></tr>

<tr><td valign="top" colspan="2" class="fieldtitle">Kortele leidžiama naudotis valandomis:</td><td valign="top" class="fieldtitle">Mėn. kredito limitas:</td></tr>
<tr>
<td valign="middle" colspan="2">
Nuo <input maxlength="2" type="text" id="nuo" name="nuo" class="inp" style="width:100px;" value="<?php echo htmlspecialchars($nuo);?>">
 Iki <input maxlength="2" id="iki" name="iki" type="text" class="inp" style="width:100px;" value="<?php echo htmlspecialchars($iki);?>">
</td>
<td valign="top">
<input name="crlimit" id="crlimit" class="inp" MAXLENGTH=6  type="text" value="<?php echo htmlspecialchars($crlimit);?>">

</td></tr>
<tr><td valign="top" colspan="2" class="fieldtitle">Kortelės neaptarnauti savaitės dienomis:</td><td valign="top" class="fieldtitle"></td></tr>
<tr>
<td valign="middle" colspan="2">
<div style="text-align:left;margin-bottom:10px;">


<table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collpase;width:100%;border: 1px solid #c2c2c2;">
<tr><th width="50" style="text-align:center;">I</th>
<th width="50" style="text-align:center;">II</th>
<th width="50" style="text-align:center;">III</th>
<th width="50" style="text-align:center;">IV</th>
<th width="50" style="text-align:center;">V</th>
<th width="50" style="text-align:center;">VI</th>
<th width="50" style="text-align:center;">VII</th></tr>
<tr>
<td style="text-align:center;"><input type="checkbox" id="p1" name="p1" <?php if ($p1 == "1") echo"checked";?>></td>
<td style="text-align:center;"><input type="checkbox" id="p2" name="p2" <?php if ($p2 == "1") echo"checked";?>></td>
<td style="text-align:center;"><input type="checkbox" id="p3" name="p3" <?php if ($p3 == "1") echo"checked";?>></td>
<td style="text-align:center;"><input type="checkbox" id="p4" name="p4" <?php if ($p4 == "1") echo"checked";?>></td>
<td style="text-align:center;"><input type="checkbox" id="p5" name="p5" <?php if ($p5 == "1") echo"checked";?>></td>
<td style="text-align:center;"><input type="checkbox" id="p6" name="p6" <?php if ($p6 == "1") echo"checked";?>></td>
<td style="text-align:center;"><input type="checkbox" id="p7" name="p7" <?php if ($p7 == "1") echo"checked";?>></td>
</tr>
</table>
</div>

</td>
<td valign="top">
</td></tr>

</table>


</td><td class="rightcol">
<?php

?>


</td></tr>
<tr><td>&nbsp;</td><td colspan="2">

</td></tr>
</table>
</form>
<?php
include("footer.php");
?>